<?php
if(!function_exists("_stime")){
	function _stime( $time ){
		$today = strtotime("today");
		$tomorrow = strtotime("+1 day");
		$ototoi = strtotime("+2 days");
		
		if( $time >= $today && $time < $tomorrow ){
			return "Hôm nay";
		}		

		if( $time >= $tomorrow && $time < $ototoi ){
			return "Ngày kia";
		}		
		return date("d/m/Y",$time);
	}
}	
?>
<table class="home-table" width="1230" height="100%" cellpadding="0" cellspacing="0">
<tr>
	<td class="home-side-container" valign="top">
		<div class="home-side">
			<div class="home-side-title">Thông tin cá nhân</div>
			<div class="home-user">
			<?php $user = $this->get("user");?>
			<div id="home-photo" onmouseover="$('#user_form_photo').css('visibility:visible')" onmouseout="$('#user_form_photo').css('visibility:hidden')">
				<a class="home-edit-icon" id="user_form_photo">
				<script type="text/javascript">
					user_form_upload_photo();
				</script>
				</a>
				<a id="user_form_photo_progress"></a>
				<?php if($user['photo']):?>
				<img id='uphoto' class="userimg home-photo" src="<?php _baseUrl()?>/files/photo/<?php _e($user['photo'])?>"/>
				<?php else:?>
				<img id='uphoto' class="userimg home-photo" src="<?php _baseUrl()?>/style/images/home-nophoto.png"/>
				<?php endif;?>
			</div>	
			<a class="home-username"><?php _e(get_user_link($user));?></a><br/>
			<span class="home-last-act">Đăng nhập <?php _e(show_smart_time($user['date_login']));?></span>	
			<br/><a onclick="load_inframe('<?php _baseUrl();?>/User/Config',{title:'Cập nhập thông tin cá nhân'})">&#187;<u>Thông tin cá nhân</u></a>
			<br/><a onclick="load_inframe('<?php _baseUrl();?>/User/Password',{title: 'Đổi mật khẩu đăng nhập'})">&#187;<u>Đổi mật khẩu</u></a>
			<div style="clear:both"></div>
			</div>
			
			<ul class="home-menu">
				<li>
					<a href="#" class="home-message-menu">Tin nhắn chưa đọc</a>
				</li>
				<li>
					<a href="#" class="home-email-menu">Email mới nhận</a>
				</li>
				<li>
					<a href="#" class="home-notice-menu">Cảnh báo</a>
				</li>
				<li>
					<a href="#Task/Index/Index?order_by=date_created&order_type=desc" class="home-task-menu">Công việc mới</a>
					<?php $t = $this->get('total_task_new');?>
					<?php if( $t > 0):?>
					<span class="home-number"><?php _e($t);?></span>
					<?php endif;?>					
				</li>
				<li>
					<a href="#Task/Index/Index?order_by=date_end&order_type=desc" class="home-tasktime-menu">Deadline công việc</a>
					<?php $t = $this->get('total_task_deadline');?>
					<?php if( $t > 0):?>
					<span class="home-number"><?php _e($t);?></span>
					<?php endif;?>
				</li>
				<li>
					<a href="#" class="home-diploma-menu">Công văn mới</a>
				</li>
			</ul>
			<!--USER ONLINE-->
			<div id="home-content">
				<div class="home-content-title" style="border:none;background-image:none;font-size:11px!important;padding-left:5px;border-bottom:1px solid #ccc;border-top:1px solid #ccc">Online hôm nay:</div>	
				<div style="background:#fff;padding:15px">
					<?php $a=array();?>
					<?php foreach( $this->get('users') as $u ):?>
					<?php $a[]=  "<span title='".show_date(DATETIME_FORMAT,$u['date_login'])."'><a class='chaticon-{$u['ID']}'><span class='offline'></span></a> ".get_user_link($u) . "</span>";?>
					<?php endforeach;?>	
					<?php _e(implode(",  ",$a));?>
				</div>
			</div>	
			
	</div></td>
	<td class="home-content-container" valign="top">
		<div id="home-content">
			<div class="home-content-title">Thông tin cơ quan</div>	
			<table border="0" cellpadding="4">
				<tr>
					<td width="315">
						<div class="home-box">
							<h2 class="home-box-title home-calendar-icon">Lịch biểu mới &#187;</h2>
							<?php $ar = $this->get('calendars');?>
							<ul class="home-list">
								<?php foreach( $ar as $a ):?>
								<li><?php _e(_stime(strtotime( str_replace("-","/",$a['date_start'])." ".$a['time_start'] ) ));?>, 
								<span title="Đến <?php _e(date("H:i",strtotime(date('Y-m-d')." {$a['time_end']}")));?>"><?php _e(date("H:i",strtotime(date('Y-m-d')." {$a['time_start']}")));?> </span>
									<a href="#Calendar/Company/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['title'],27));?></a></li>
								<?php endforeach;?>
							</ul>							
						</div>
					</td>
					<td width="315">
						<div class="home-box">
							<h2 class="home-box-title  home-task-icon">Công việc &#187;</h2>
							<?php $tasks = $this->get('tasks');?>
							<?php if( count($tasks) > 0):?>
							<ul class="home-list home-task">
								<?php foreach( $tasks as $a ):?>
								<li><a href="#Task/Index/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['title'],50));?></a></li>
								<?php endforeach;?>
							</ul>
							<?php endif;?>
						</div>
					</td>
					<td width="315">
						<div class="home-box">
							<h2 class="home-box-title home-diploma-icon">Crm mới &#187;</h2>
							<?php $posts = $this->get('crms');?>
							<?php if( count($posts) > 0):?>
							<ul class="home-list home-diploma">
								<?php foreach( $posts as $a ):?>
								<li><a href="#Crm/Customer/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['name'],40));?></a></li>
								<?php endforeach;?>
							</ul>
							<?php endif;?>							
						</div>
					</td>
				</tr>			
				<tr>
					<td width="315">
						<div class="home-box">
							<h2 class="home-box-title home-news-icon">Tin tức &#187;</h2>
							<?php $news = $this->get('news');?>
							<?php if( count($news) > 0):?>
							<ul class="home-list home-news">
								<?php foreach( $news as $a ):?>
								<li><a href="#News/Index/View?ID=<?php _e($a['ID']);?>"><?php _e(short_title($a['title'],100));?></a></li>
								<?php endforeach;?>
							</ul>
							<?php endif;?>								
						</div>
					</td>
					<td colspan="2">
						<div class="home-box">
							<div style="text-align:left">
								<h2 class="home-box-title home-chart-icon" style="display:inline-block">Biểu đồ dự án</h2></div>
							<center>
							<div id="chart">
								<?php foreach( $this->get('projects') as $i => $a ):?>
								<a href="#Project/Index/View?ID=<?php _e($a['ID'])?>"><div class="bar" title="<?php _e($a['title']);?>" style="left:<?php _e(10+35*$i);?>px;height:<?php _e(max(1,(int)$a['rate']))?>%">
									<div class="label">DA<?php _e($i+1);?></div>
									<div style="position:absolute;top:-16px;width:30px;text-align:center"><?php _e($a['rate']);?>%</div>
								</div></a>
								<?php endforeach;?>
								
								<div class="horizal">
									<!--extend y axis-->
									<div style="position:absolute;top:-15px;left:0px;width:1px;	background:#5755A9;height:25px">
									<div style="font-size:9px;display:inline-block;position:absolute;top:-10px;left:-4px;color:#5755A9">▲</div>	
									</div>
									<!--stone y-->
									<?php for( $j=2; $j < 11; $j=$j+2 ):?>
									<span style="margin-bottom:-5px;padding:0px;font-size:9px;display:inline-block;position:absolute;bottom:<?php _e($j*10);?>%;white-space:nowrap;right:0px;color:#5755A9">
										<?php _e($j*10);?> -</span>	
									<?php endfor;?>									
								</div>
								<div class="vertical">
									<div style="font-size:9px;display:inline-block;position:absolute;top:-6px;right:-4px;color:#5755A9">►</div>	
								</div>		
								<!--desc-->
								<div style="width:180px;height:190px;border:1px solid #ddd;border-bottom:3px double #ddd;border-top:3px double #ddd;padding:5px;position:absolute;z-index:5;right:-27px;top:-55px">
									<table border="0" cellpadding="3" align="left" width="100%">
									<?php foreach( $this->get('projects') as $i => $a ):?>
									<tr>
										<td width="10">
											<span style="font-size:10px">DA<?php _e($i+1)?></span>
										</td>
									<td>
									<a style="display:block;font-size:10px" href="#Project/Index/View?ID=<?php _e($a['ID'])?>">
										<?php _e(short_title($a['title'],27)) ?>
									</a>
									</td></tr>
									<?php endforeach;?>
									</table>
								</div>
							</div>
							</center>
						</div>
					</td>
				</tr>				
			</table><div style='clear:both;height:1px'></div>
		</div>
	</td>
</tr>
</table>
<br/><br/>